package com.yutel.system.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.support.JdbcDaoSupport;

import com.yutel.system.dao.ISysUserDao;
import com.yutel.system.repository.SysUser;

public class SysUserDao extends JdbcDaoSupport implements ISysUserDao {
	
	public SysUser checkLogin(String loginName, String password, String status) {
		String sql = "select * from xs_user where login_name='"+ loginName+"' and password='"+password+"'";
		List<SysUser> list = getJdbcTemplate().query(sql, new UserRowMapper());
		if (list.size() == 1) {
			return list.get(0);
		} else {
			return null;
		}
	}
	private class UserRowMapper implements RowMapper {
		public Object mapRow(ResultSet rs, int index) throws SQLException {
			SysUser user = new SysUser();
			user.setUserId(rs.getInt("user_id"));
			user.setUserName(rs.getString("user_name"));
			user.setLoginName(rs.getString("login_name"));
			user.setPassword(rs.getString("password"));
			user.setSex(rs.getString("sex"));
			return user;
		}
	}
}
